﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Model;
using Bll;

namespace 财会系
{
    public partial class Search : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                dataBind();
                if (Request.QueryString["title"] != null)
                {
                    ModelIndex m = new ModelIndex();
                    m.Title = Request.QueryString["title"].ToString();

                    datatshow(m);
                }
                else
                {
                    Response.Redirect("index.aspx");
                }
            }
        }

        public void dataBind()
        {
            //导航菜单栏的名称开始
            lblSiteMap.Text = "搜索";
            //导航菜单栏的名称结束

            //子菜单栏列表开始

            lblSubNavShowName1.Text = "搜索";
            //子菜单栏列表结束
        }

        public void datatshow(ModelIndex m)
        {
            DataView dv = new DataView();

            BllIndex b = new BllIndex();

            DataSet ds = b.Retrieve_Information_All(m);

            dv.Table = ds.Tables[0];
            dv.Sort = "DateTime desc";

            GVSearch.DataSource = dv;
            GVSearch.DataBind();
        }

        protected void GVSearch_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#ffffff'");
            }

            GridViewRow gvr = e.Row;
            switch (gvr.RowType)
            {
                case DataControlRowType.DataRow:
                    {
                        // Retrieve controls
                        LinkButton link1 = gvr.FindControl("LinkButton2") as LinkButton;
                        if (link1 != null)
                        {
                            link1.CommandArgument = gvr.RowIndex.ToString();
                        }
                        break;
                    }
            }
        }

        protected void GVSearch_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GVSearch.PageIndex = e.NewPageIndex;
            if (Request.QueryString["title"] != null)
            {
                ModelIndex m = new ModelIndex();
                m.Title = Request.QueryString["title"].ToString();

                datatshow(m);
            }

        }

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            LinkButton link1 = sender as LinkButton;
            int rowIndex = Int32.Parse(link1.CommandArgument);

            string id = ((Label)(GVSearch.Rows[rowIndex].FindControl("lblId"))).Text;
            string navid = ((Label)(GVSearch.Rows[rowIndex].FindControl("lblNavId"))).Text;

            if (navid == "")
                Response.Redirect("./Piece.aspx?type=5&Nav=11&Id=" + id + "&Web=");
            if (navid != "2")
                Response.Redirect("./Piece.aspx?type=6&Nav=" + navid + "&Id=" + id + "&Web=");
            else
                Response.Redirect("./Piece.aspx?type=2&Nav=" + navid + "&Id=" + id + "&Web=");
        }
    }
}